/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/valid-parentheses
   @Language: C++
   @Datetime: 19-05-30 13:34
   */

class Solution {
public:
	bool isValid(string s) {
		stack<char> sta;
		for(const char &c:s){
			if(c=='(' || c=='[' || c=='{') sta.push(c);
			else if(c==')')
				if(sta.size() && sta.top()=='(') sta.pop();
				else return false;
			else if(c==']')
				if(sta.size() && sta.top()=='[') sta.pop();
				else return false;
			else if(c=='}')
				if(sta.size() && sta.top()=='{') sta.pop();
				else return false;
		}
		return sta.size()==0;
	}
};
